<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>API首页-AphpAdmin</title>
    <link rel="shortcut icon" href="__ROOT__/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="__STATIC__/component/layui/css/layui.css"/>
    <style>
        .layui-warp {
            max-width: 980px;
            margin: 0 auto 15px auto;
            padding: 10px;
        }
        .layui-warp h1 {
            margin: 10px 0;
        }
        .layui-warp h2 {
            margin: 13px 0;
        }
        .layui-warp p {
            padding: 10px;
        }
        .layui-warp a {
            color: #337ab7;
            font-weight: bold;
        }
        .layui-warp .blue {
            color: #337ab7;
        }
    </style>
</head>
<body>
<div class="layui-warp">
    菜单：<a href="__HOST__">前台</a> | <a href="__HOST__/api.php">API</a> | <a href="__HOST__/admin.php">后台</a>
    <h1>API首页</h1>
    <p>这是 <strong class="layui-font-purple">一鱼CRUD后台AphpAdmin</strong> 的API首页，可以自由修改，添加接口方法快速调用数据。</p>

    <h2>接口示例</h2>
    <p>文件：<span class="blue">app/api/controller/Test.php</span>：</p>
    <pre class="layui-code code-demo" lay-options="{theme: 'dark'}">
namespace app\api\controller;
class Test extends Base
{
    // 默认接口
    public function index()
    {
        $this->_json(200, '', ['name' => 'AphpAdmin_v1']);
    }
    // 直接获取
    public function get1()
    {
        return db('test')->where('status=1')->cache()->select();
    }
    // 通用获取
    public function get2()
    {
        $data = db('test')->where('status=1')->cache()->select();
        if (empty($data)) {
            $this->error('记录不存在');
        }
        $this->_json(200, '请求成功', $data);
    }
}
    </pre>
    <p>接口测试链接：<a href="{:url('test/index')}" target="_blank">默认</a> | <a href="{:url('test/get1')}" target="_blank">直接获取</a> | <a href="{:url('test/get2')}" target="_blank">通用获取</a></p>
    <h2>对接接口</h2>
    <p>用AJAX请求：<span class="blue">{:url('test/get2')}</span></p>
    <h2>返回设置</h2>
    <p>可在 <span class="blue">config/response.php</span> 设置返回字段：</p>
    <pre class="layui-code code-demo" lay-options="{theme: 'dark'}">
'ret' => 'code', // 状态码字段
'msg' => 'msg', // 返回信息字段
'data' => 'data', // 返回数据字段
'status' => 'status', // 状态字段：1成功(状态码<400)，0失败(状态码>=400)
    </pre>

    <h2>技术支持</h2>
    <p>
        框架官网：<a href="https://www.aphp.top" target="_blank">aphp.top</a>
        | CMS官网：<a href="https://www.aphpcms.com" target="_blank">aphpcms.com</a>
        | 技术联系：无念(24203741@qq.com) | Powered by AphpAdmin v1.0
    </p>
</div>

<script src="__STATIC__/component/layui/layui.js"></script>
<script>
    layui.use(function () {
        layui.code({
            elem: '.code-demo'
        });
    });
</script>
</body>
</html>